using System;
using System.Collections;
using System.Data;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using PHSRAG.Insight21.Agreements;
using PHSRAG.Insight21.Common.Pages;
using PHSRAG.Insight21.Context;
using PHSRAG.Insight21.InsightWebControls;
using PHSRAG.Insight21.Policy;
using PHSRAG.Insight21.SearchContext;
using PHSRAG.Security.Enumerations;
using PHSRAG.Utility;
using PHSRAG.SharePointUtility;
using PHSRAG.Security;
using System.Xml;
using System.IO;
using System.Text;
using System.Net.Mail;
using PHSRAG.Insight21.CDS;
using PHSRAG.WebControls;
using System.Security.Principal;
using Constants = PHSRAG.Insight21.InsightUtilities.Constants;
using Helper = PHSRAG.WebControls.Helper;

namespace PHSRAG.Insight21.Agreements
{
    public partial class AdvanceFundRequestReview : NoCachePage
    {
        #region Constants

        private const string PageCacheKey = "AdvanceFundRequestReviewpageCacheKey_19309A7A-1206-497d-8D9F-189E5152CE59";
        private const string CurrentPageIndexKey = "AdvanceFundRequestReviewIndexKey_119B5DD3-0ED1-45f0-B455-6F9C0473E580";
        private const string PropNum = "AdvanceFundRequestLandingPropNum_B6836CCD-FA0B-4690-A0FC-52352E590F6C";
        private const string PageName = "Advance Fund Request Review";

        #endregion

        #region Enums (Private)

        private enum WorkflowStatus
        {
            Draft = 1,
            AwaitingPISignoff,
            AwaitingDepartmentSignoff,
            AwaitingGASignoff,
            Completed,
            Denied
        }

        #endregion

        #region Private Variables

        private ICachePolicy cachePolicy;
        private ICachePolicy pageCachePolicy;
        private int loggedInUserID;
        private static int loggedID;
        private DataTable dtGrid;
        private string EmailTemplate = "";
        private string PageUrl = "";

        #endregion

        #region Private Properties

        /// <summary>
        /// Get/Set the current page within the datagrid for display. This information persists across page loads.
        /// </summary>
        private int CurrentPageIndex
        {
            get
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.AdvanceFundRequestReviewPageKey) as Hashtable;
                return (h == null || h[CurrentPageIndexKey] == null) ? 0 : (int)h[CurrentPageIndexKey];
            }
            set
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.AdvanceFundRequestReviewPageKey) as Hashtable ?? new Hashtable();
                h[CurrentPageIndexKey] = value;

                pageCachePolicy.Cache(Keys.AdvanceFundRequestReviewPageKey, h);
            }
        }

        private string ProposalNumber
        {
            get
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.AdvanceFundRequestLandingPageKey) as Hashtable;
                return (h == null || h[PropNum] == null) ? "" : h[PropNum].ToString();
            }
            set
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.AdvanceFundRequestLandingPageKey) as Hashtable ?? new Hashtable();
                h[PropNum] = value;

                pageCachePolicy.Cache(Keys.AdvanceFundRequestLandingPageKey, h);
            }
        }

        #endregion
        
        #region Event Handlers

        protected override void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);

            cachePolicy = (Policy.ICachePolicy)Session[Policy.Names.CachePolicyKey];
            pageCachePolicy = (Policy.ICachePolicy)Session[Policy.Names.PageCachePolicyKey];
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                int Status = 0;
                annunciator.Message = string.Empty;
                breadCrumb.Add("Advance Fund Request", Settings.GetKeyValue("SubNavigation.Agreements.AdvanceFundRequestLandingURL", ""), 1);
                breadCrumb.Add("Advance Request Review", Settings.GetKeyValue("SubNavigation.Agreements.AdvanceFundRequestReviewURL", ""), 2);
                                
                loggedInUserID = ((UserContext)cachePolicy.GetCachedObject(UserContext.CacheKey)).DomainUserId;
                loggedID = loggedInUserID;

                // setting the insight url for the email link based on the current environment.                
                PageUrl = Utility.Settings.GetKeyValue("Email.AdvanceFundRequest.LinkUrl", "https://insight.partners.org/Agreements/AdvanceFundRequestForm.aspx");                             

                Panel3.Visible = false;
                Panel4.Visible = false;
                Panel5.Visible = false;
                Panel6.Visible = false;
                Panel7.Visible = false;
                DataTable dt = null;

                string QueryString = ProposalNumber;
                if (QueryString != "0")
                {
                    dt = GetInfoByProposalNumber(QueryString);
                    if (dt.Rows.Count > 0)
                    {
                        LoadPageData(dt);
                    }

                    //check the workflow status for this fund request.
                    Status = Convert.ToInt32(dt.Rows[0]["Status"].ToString());
                    if (Status == (int)WorkflowStatus.AwaitingPISignoff)
                    {
                        if (Convert.ToInt32(dt.Rows[0]["PIId"].ToString() == "" ? "0" : dt.Rows[0]["PIId"].ToString()) == loggedInUserID)
                        {
                            Panel3.Visible = true;
                        }
                    }
                    else if (Status == (int)WorkflowStatus.AwaitingDepartmentSignoff)
                    {
                        if (Convert.ToInt32(dt.Rows[0]["ChiefId"].ToString() == "" ? "0" : dt.Rows[0]["ChiefId"].ToString()) == loggedInUserID || Convert.ToInt32(dt.Rows[0]["DelegateId"].ToString() == "" ? "0" : dt.Rows[0]["DelegateId"].ToString()) == loggedInUserID)
                        {
                            Panel3.Visible = true;
                        }
                    }
                    else if (Status == (int)WorkflowStatus.AwaitingGASignoff)
                    {
                        if (Convert.ToInt32(dt.Rows[0]["GAId"].ToString() == "" ? "0" : dt.Rows[0]["GAId"].ToString()) == loggedInUserID)
                        {
                            Panel3.Visible = true;
                        }
                    }
                }
                
                if (!IsPostBack)
                {      
                    // populate the previous comments.
                    dt = GetCommentsByProposalNumber(QueryString);
                    string Comm = "";
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            Comm = Comm + dr["Comment"].ToString() + Environment.NewLine;
                        }
                    }
                    lblComments.Text = Comm;

                    bool AuthReq = false;
                    if (Utility.Settings.GetKeyValue("ADAuthentication", "false").ToString() == "true")
                    {
                        AuthReq = true;
                    }
                    imgBtnSubmitPI.OnClientClick = "javascript:return ValidateSubmissionPI('" + AuthReq + "');";
                    imgBtnSubmitCOS.OnClientClick = "javascript:return ValidateSubmissionCOS('" + AuthReq + "');";
                    imgBtnSubmitGA.OnClientClick = "javascript:return ValidateSubmissionGA('" + AuthReq + "');";
                    imgBtnDenial.OnClientClick = "javascript:return ValidateDenial();";
                    
                    // populate the attachments
                    dt = GetUploadedDocument(QueryString);
                    if (dt.Rows.Count > 0)
                    {
                        gvDocs.DataSource = dt;
                        gvDocs.DataBind();

                        foreach (GridViewRow row in gvDocs.Rows)
                        {
                            ImageButton lnkAction = (ImageButton)row.Cells[3].FindControl("ibView");
                            lnkAction.OnClientClick = "javascript:window.open('../Research/downloadform.aspx?FileUrl=" + lnkAction.ToolTip.ToString() + "', 'OpenFile', 'resizable=yes, status=yes, scrollbars=yes');return false;";
                        }
                    }
                    else
                    {
                        gvDocs.DataSource = dt;
                        gvDocs.DataBind();
                    }

                    //populate the previous approvals.
                    dt = GetApprovals(QueryString);
                    gvApprovals.DataSource = dt;
                    gvApprovals.DataBind();
                }
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }

        #endregion

        #region Private Methods

        /// <summary>
        /// GetInfoByProposalNumber returns a resultset.
        /// </summary>
        /// <returns>DataTable</returns>
        private DataTable GetInfoByProposalNumber(string PropNumber)
        {
            AdvanceFundRequest ar = new AdvanceFundRequest();
            try
            {
                dtGrid = ar.GetInfoByProposalNumber(DataAccess.GetConnectionString(), PropNumber);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            return dtGrid;
        }

        private DataTable GetCommentsByProposalNumber(string PropNumber)
        {
            AdvanceFundRequest ar = new AdvanceFundRequest();
            try
            {
                dtGrid = ar.GetCommentsByProposalNumber(DataAccess.GetConnectionString(), PropNumber);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            return dtGrid;
        }

        private DataTable GetUploadedDocument(string PropNumber)
        {
            AdvanceFundRequest ar = new AdvanceFundRequest();
            try
            {
                dtGrid = ar.GetUploadedDocument(DataAccess.GetConnectionString(), PropNumber);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            return dtGrid;
        }

        private DataTable GetApprovals(string PropNumber)
        {
            AdvanceFundRequest ar = new AdvanceFundRequest();
            try
            {
                dtGrid = ar.GetApprovalsByProposalNumber(DataAccess.GetConnectionString(), PropNumber);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            return dtGrid;
        }

        private void SaveFundRequestEmailNotification(string PropNumber, int EmailedToId, int EmailedById, string Subject, string MessageBody, int StatusType)
        {
            AdvanceFundRequest ar = new AdvanceFundRequest();
            try
            {
                ar.SaveFundRequestEmailNotification(DataAccess.GetConnectionString(), PropNumber, EmailedToId, EmailedById, Subject, MessageBody, StatusType);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
        }

        private void ApproveFundRequest(string PropNumber, int CreatedBy, string FundNumber, int StatusType)
        {
            AdvanceFundRequest ar = new AdvanceFundRequest();
            try
            {
                ar.ApproveFundRequest(DataAccess.GetConnectionString(), PropNumber, CreatedBy, FundNumber, StatusType);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
        }

        private void DeclineFundRequest(string PropNumber, int CreatedBy, string Reason, int StatusType)
        {
            AdvanceFundRequest ar = new AdvanceFundRequest();
            try
            {
                ar.DeclineFundRequest(DataAccess.GetConnectionString(), PropNumber, CreatedBy, Reason, StatusType);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
        }

        public static void SendEmail(string FromEmail, string ToEmail, string EmailSubject, string EmailBody)
        {
            MailMessage mailMessage = new MailMessage(FromEmail, ToEmail);
            mailMessage.IsBodyHtml = true;

            mailMessage.Subject = EmailSubject;
            mailMessage.Body = EmailBody;

            SmtpClient client = new SmtpClient(Utility.Settings.GetKeyValue("SmtpServer", "SMTP.Partners.org"));
            client.Send(mailMessage);
        }

        private bool SendEmailNotification(string To, string Subject, string Message)
        {
            try
            {
                string From = Utility.Settings.GetKeyValue("Email.AdvanceFundRequest.Admin", "InsightHelpDesk@partners.org");
                SendEmail(From, To, Subject, Message);
            }
            catch(Exception ex)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Displays an error message on the screen to the user with the exception, and all
        /// inner exception messages.
        /// </summary>
        /// <param name="ex">The exception to report on</param>
        private void DisplayExceptionReport(Exception ex)
        {
            annunciator.Title = PHSRAG.Insight21.InsightUtilities.Constants.Annunciator.Title;
            annunciator.Message = ExceptionReport.GetExceptionInfo(ex, false);
        }

        private void LoadPageData(DataTable dt)
        {
            try
            {
                lblPI.Text = dt.Rows[0]["PIName"].ToString();
                lblTitle.Text = dt.Rows[0]["ShortTitle"].ToString();
                lblTitle.ToolTip = dt.Rows[0]["Title"].ToString();
                lblInstitution.Text = dt.Rows[0]["Organization"].ToString();
                lblCOS.Text = dt.Rows[0]["COS"].ToString();
                lblSponsor.Text = dt.Rows[0]["SponsorName"].ToString();
                lblDepartment.Text = dt.Rows[0]["Department"].ToString();
                lblProject.Text = dt.Rows[0]["PeriodDate"].ToString();
                lblResearch.Text = dt.Rows[0]["GAName"].ToString();
                lblDept.Text = dt.Rows[0]["DAName"].ToString();
                lblPropNo.Text = dt.Rows[0]["PropNumber"].ToString();
                lblStatus.Text = dt.Rows[0]["Status"].ToString();
                lblStatusName.Text = dt.Rows[0]["StatusName"].ToString();
                lblFundNumber.Text = dt.Rows[0]["FundNumber"].ToString();
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }
       
        #endregion
        
        protected void imgBtnSubmitPI_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (Utility.Settings.GetKeyValue("ADAuthentication", "false").ToString() == "true")
                {
                    Authenticator.ValidateCredentials(txtUserNamePI.Text.Trim(), txtPasswordPI.Text.Trim());
                }

                int Status = (int)WorkflowStatus.AwaitingDepartmentSignoff;
                string EmailSubject = "ACTION: Advance Fund Request Requires Your Approval";
                string EmailId = "";
                string Requestor = "";
                ApproveFundRequest(lblPropNo.Text.Trim(), loggedInUserID, "", Status);
                // Send mail notification
                DataTable dt = GetInfoByProposalNumber(lblPropNo.Text.Trim());
                EmailId = dt.Rows[0]["ChiefEmailId"].ToString() + ";" + dt.Rows[0]["DelegateEmailId"].ToString();
                Requestor = dt.Rows[0]["PIName"].ToString();               
                CreateEmailMessage(Requestor, dt.Rows[0]["Title"].ToString(), dt.Rows[0]["PIName"].ToString(), dt.Rows[0]["SponsorName"].ToString(), dt.Rows[0]["PeriodDate"].ToString(), EmailSubject, EmailId);  

                Panel3.Visible = false;
                Panel4.Visible = false;
                Panel7.Visible = false;

                //populate the previous approvals.
                dt = GetApprovals(lblPropNo.Text.Trim());
                gvApprovals.DataSource = dt;
                gvApprovals.DataBind();
                annunciator.Message = "Fund Request approved successfully.";
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }

        protected void imgBtnSubmitCOS_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (Utility.Settings.GetKeyValue("ADAuthentication", "false").ToString() == "true")
                {
                    Authenticator.ValidateCredentials(txtUserNameCOS.Text.Trim(), txtPasswordCOS.Text.Trim());
                }

                int Status = (int)WorkflowStatus.AwaitingGASignoff;
                string EmailSubject = "ACTION: Advance Fund Request Requires Your Approval";
                string EmailId = "";
                string Requestor = "";
                ApproveFundRequest(lblPropNo.Text.Trim(), loggedInUserID, "", Status);
                // Send mail notification
                DataTable dt = GetInfoByProposalNumber(lblPropNo.Text.Trim());
                EmailId = dt.Rows[0]["GAEmailId"].ToString();
                Requestor = dt.Rows[0]["ChiefName"].ToString();
                CreateEmailMessage(Requestor, dt.Rows[0]["Title"].ToString(), dt.Rows[0]["PIName"].ToString(), dt.Rows[0]["SponsorName"].ToString(), dt.Rows[0]["PeriodDate"].ToString(), EmailSubject, EmailId);  

                Panel3.Visible = false;
                Panel5.Visible = false;
                Panel7.Visible = false;

                //populate the previous approvals.
                dt = GetApprovals(lblPropNo.Text.Trim());
                gvApprovals.DataSource = dt;
                gvApprovals.DataBind();
                annunciator.Message = "Fund Request approved successfully.";
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }

        protected void imgBtnSubmitGA_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (Utility.Settings.GetKeyValue("ADAuthentication", "false").ToString() == "true")
                {
                    Authenticator.ValidateCredentials(txtUserNameGA.Text.Trim(), txtPasswordGA.Text.Trim());
                }

                int Status = (int)WorkflowStatus.Completed;
                string EmailSubject = "Advance Fund Request Has Been Approved";
                string EmailId = "";
                string[] EId = null;
                ApproveFundRequest(lblPropNo.Text.Trim(), loggedInUserID, txtFundNumber.Text.Trim(), Status);
                // Send mail notification
                DataTable dt = GetInfoByProposalNumber(lblPropNo.Text.Trim());
                EmailId = dt.Rows[0]["PIEmailId"].ToString() + ";" + dt.Rows[0]["DAEmailId"].ToString() + ";" + dt.Rows[0]["SubmitterEmailId"].ToString();
                EmailTemplate = "<html>The advance fund request has been approved for the following project.  Once the finalized sponsor award notice has been received, the same fund will be used and the award project budget authorized on your Insight financial statement:";
                EmailTemplate = EmailTemplate + "<br><br><ul>";
                EmailTemplate = EmailTemplate + "<li>" + "Approver : " + dt.Rows[0]["GAName"].ToString() + "</li>";
                EmailTemplate = EmailTemplate + "<li>" + "Approved Date : " + DateTime.Today.ToShortDateString() + "</li>";
                EmailTemplate = EmailTemplate + "<li>" + "Fund Number : " + txtFundNumber.Text.Trim() + "</li>";
                EmailTemplate = EmailTemplate + "<li>" + "Project Title : " + dt.Rows[0]["Title"].ToString() + "</li>";
                EmailTemplate = EmailTemplate + "<li>" + "PI : " + dt.Rows[0]["PIName"].ToString() + "</li>";
                EmailTemplate = EmailTemplate + "<li>" + "Sponsor : " + dt.Rows[0]["SponsorName"].ToString() + "</li>";
                EmailTemplate = EmailTemplate + "<li>" + "Project S/E Date : " + dt.Rows[0]["PeriodDate"].ToString() + "</li>";
                EmailTemplate = EmailTemplate + "</ul><br>";
                EmailTemplate = EmailTemplate + "Link to form within Insight to approve" + "<br>" + PageUrl + "?id=" + lblPropNo.Text.Trim() + "</html>"; //"http://PHSRAGB/Insight_4/Agreements/AdvanceFundRequestForm.aspx?id=" + lblPropNo.Text.Trim() + "</html>";                        
                EId = EmailId.Split(';');
                for (int i = 0; i < EId.Length; i++)
                {
                    SendEmailNotification(EId[i].ToString(), EmailSubject, EmailTemplate);
                }
                Panel3.Visible = false;
                Panel6.Visible = false;
                Panel7.Visible = false;

                //populate the previous approvals.
                dt = GetApprovals(lblPropNo.Text.Trim());
                gvApprovals.DataSource = dt;
                gvApprovals.DataBind();
                annunciator.Message = "Fund Request approved successfully.";
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }        

        protected void imgBtnDenial_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                int Status = (int)WorkflowStatus.Denied;
                string EmailSubject = "Advance Fund Request Has Been Declined";
                string EmailId = "";
                string[] EId = null;
                DataTable dt = null;
                if (txtDenial.Text.Trim() != "")
                {
                    DeclineFundRequest(lblPropNo.Text.Trim(), loggedInUserID, txtDenial.Text.Trim(), Status);
                    
                    // Send mail notification
                    dt = GetInfoByProposalNumber(lblPropNo.Text.Trim());
                    EmailTemplate = "<html>" + Utility.Settings.GetKeyValue("Email.AdvanceFundRequest.DeclineBody", "The advance fund request has been decline.  Please review the following information to view the reason.");
                    EmailTemplate = EmailTemplate + "<br><br><ul>";
                    
                    if (lblStatus.Text == "2")
                    {   
                        EmailId = dt.Rows[0]["SubmitterEmailId"].ToString();
                        EmailTemplate = EmailTemplate + "<li>" + "Requestor : " + dt.Rows[0]["PIName"].ToString() + "</li>";                        
                    }
                    else if (lblStatus.Text == "3")
                    {
                        EmailId = dt.Rows[0]["PIEmailId"].ToString() + ";" + dt.Rows[0]["DAEmailId"].ToString() + ";" + dt.Rows[0]["SubmitterEmailId"].ToString();
                        EmailTemplate = EmailTemplate + "<li>" + "Requestor : " + dt.Rows[0]["ChiefName"].ToString() + "</li>";                        
                    }
                    else if (lblStatus.Text == "4")
                    {
                        EmailId = dt.Rows[0]["DAEmailId"].ToString() + ";" + dt.Rows[0]["SubmitterEmailId"].ToString();
                        EmailTemplate = EmailTemplate + "<li>" + "Requestor : " + dt.Rows[0]["GAName"].ToString() + "</li>";  
                    }

                    EmailTemplate = EmailTemplate + "<li>" + "Requested Date : " + DateTime.Today.ToShortDateString() + "</li>";
                    EmailTemplate = EmailTemplate + "<li>" + "Project Title : " + dt.Rows[0]["Title"].ToString() + "</li>";
                    EmailTemplate = EmailTemplate + "<li>" + "PI : " + dt.Rows[0]["PIName"].ToString() + "</li>";
                    EmailTemplate = EmailTemplate + "<li>" + "Sponsor : " + dt.Rows[0]["SponsorName"].ToString() + "</li>";
                    EmailTemplate = EmailTemplate + "<li>" + "Project S/E Date : " + dt.Rows[0]["PeriodDate"].ToString() + "</li>";
                    EmailTemplate = EmailTemplate + "</ul><br>";
                    EmailTemplate = EmailTemplate + "Link to form within Insight to approve" + "<br>" + PageUrl + "?id=" + lblPropNo.Text.Trim() + "</html>"; //"http://PHSRAGB/Insight_4/Agreements/AdvanceFundRequestForm.aspx?id=" + lblPropNo.Text.Trim() + "</html>";                        
                    EId = EmailId.Split(';');
                    for (int i = 0; i < EId.Length; i++)
                    {
                        SendEmailNotification(EId[i].ToString(), EmailSubject, EmailTemplate);
                    }
                    Panel3.Visible = false;
                    Panel4.Visible = false;
                    Panel5.Visible = false;
                    Panel6.Visible = false;
                    Panel7.Visible = false;
                    
                    //populate the previous approvals.
                    dt = GetApprovals(lblPropNo.Text.Trim());
                    gvApprovals.DataSource = dt;
                    gvApprovals.DataBind();
                    annunciator.Message = "Fund Request has been declined.";
                }               
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }
        protected void rbApprove_CheckedChanged(object sender, EventArgs e)
        {
            if (rbApprove.Checked)
            {
                Panel7.Visible = false;
                if (lblStatus.Text == "2")
                {
                    Panel4.Visible = true;
                    txtDateTimePI.Text = DateTime.Now.ToShortDateString();
                    txtDateTimePI.Enabled = false;
                }
                else if (lblStatus.Text == "3")
                {
                    Panel5.Visible = true;
                    txtDateTimeCOS.Text = DateTime.Now.ToShortDateString();
                    txtDateTimeCOS.Enabled = false;
                }
                else if (lblStatus.Text == "4")
                {
                    Panel6.Visible = true;
                    txtDateTimeGA.Text = DateTime.Now.ToShortDateString();
                    txtDateTimeGA.Enabled = false;
                }
            }            
        }
        protected void rbDecline_CheckedChanged(object sender, EventArgs e)
        {
            if (rbDecline.Checked)
            {
                Panel7.Visible = true;
                Panel4.Visible = false;
                Panel5.Visible = false;
                Panel6.Visible = false;
            }  
        }

        private void CreateEmailMessage(string Requestor, string Title, string PIName, string Sponsor, string ProjDate, string EmailSubject, string EmailId)
        {
            EmailTemplate = "<html>" + Utility.Settings.GetKeyValue("Email.AdvanceFundRequest.Body", "ACTION NEEDED: An advance fund request has been submitted for your approval. Pls. review the following information and use the link included to take action.");
            EmailTemplate = EmailTemplate + "<br><br><ul>";
            EmailTemplate = EmailTemplate + "<li>" + "Requestor : " + Requestor + "</li>";
            EmailTemplate = EmailTemplate + "<li>" + "Requested Date : " + DateTime.Today.ToShortDateString() + "</li>";
            EmailTemplate = EmailTemplate + "<li>" + "Project Title : " + Title + "</li>";
            EmailTemplate = EmailTemplate + "<li>" + "PI : " + PIName + "</li>";
            EmailTemplate = EmailTemplate + "<li>" + "Sponsor : " + Sponsor + "</li>";
            EmailTemplate = EmailTemplate + "<li>" + "Project S/E Date : " + ProjDate + "</li>";
            EmailTemplate = EmailTemplate + "</ul><br>";
            EmailTemplate = EmailTemplate + "Link to form within Insight to approve" + "<br>" + PageUrl + "?id=" + lblPropNo.Text.Trim() + "</html>";

            string[] EId = EmailId.Split(';');
            for (int i = 0; i < EId.Length; i++)
            {
                SendEmailNotification(EId[i].ToString(), EmailSubject, EmailTemplate);
            }
        }
    }
}